#!/usr/bin/perl
#act_vgcreate.cgi
require './lvm-lib.pl';
&ReadParse();
my (@freepv, $vgname, $err_msg, @vginfo, $vg, $fpnum);
@freepv = split("\0", $in{'freepv'});

$vgname = $in{'vgname'};
if(!$vgname || !($vgname =~ /\S/)){
	$err_msg = $text{'err_novgname'};
	goto ERROR_OUT;
}

@vginfo = get_vg_info();
foreach $vg (@vginfo) {
	if ($vg->{'vg'} eq $vgname) {
		$err_msg = $text{'err_vgnameused'};
		goto ERROR_OUT;
	}
}

$fpnum = @freepv;
if($fpnum < 1){
        $err_msg = $text{'err_nopvselect'}; 
        goto ERROR_OUT;
}

my $rc = create_vg($vgname, @freepv);
if(!$rc){
	&redirect("index.cgi");
}else{
	$err_msg = $text{'err_createvg'}; #"VG create failed.";
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
